779D - String Game - CodeForces Solution


binary search strings *1700

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>
#define ll             long long
#define pb             push_back
#define all(v)         v.begin(),v.end()
#define fr(i,s,e)      for(ll i=s;i<e;i++)
#define rfr(i,e,s)     for(ll i=e;i>=s;i--)
#define endl           "\n"
#define sz(a)          (ll)a.size()
#define mem1(a)        memset(a,-1,sizeof(a))
#define pii            pair<ll,ll>
#define ff             first
#define ss             second
#define mod            1000000000000000007
#define fast           ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
using namespace std;


bool check(string s , string p){
    ll d = p.size() , j = 0 ;
    for(auto x : s ){
        if(x==p[j]) j+=1;
        if(j==d) return 1 ;
    }
    return 0 ;
}

int main(){
    string s , p ;
    cin >> s >> p ;

    ll n = s.size() ;
    ll a[n+1] , lo = 1 , hi = n , res = 0 ;

    fr(i,1,n+1) cin >> a[i] ;

    while( lo <= hi ){
        ll m = (lo+hi+1)/2 , j = 0  ;
        vector<ll>v(a+1,a+m+1);
        sort(all(v));
        string ss="" , ts = s ;


        for(auto x : v ) ts[x-1]='A';
        for(auto x : ts ) if(x!='A') ss+=x;
//
//        cout << m << endl;
//        cout << ss << endl;
//        cout << check(ss,p) << endl;

        if(check(ss,p)) {
            lo = m+1 ;
            res = max(res,m);
        }
        else hi = m-1 ;
    }

    cout << res << endl;

return 0 ;
}



Comments

Submit
0 Comments
More Questions

1389B - Array Walk
71B - Progress Bar
701A - Cards
545A - Toy Cars
1538E - Funny Substrings
234A - Lefthanders and Righthanders
1611D - Weights Assignment For Tree Edges
197A - Plate Game
1474A - Puzzle From the Future
6B - President's Office
1405B - Array Cancellation
431C - k-Tree
101A - Homework
1642C - Great Sequence
1523B - Lord of the Values
1406C - Link Cut Centroids
2409. Count Days Spent Together
2410. Maximum Matching of Players With Trainers
1604C - Di-visible Confusion
997A - Convert to Ones
218A - Mountain Scenery
486B - OR in Matrix
1405A - Permutation Forgery
1733A - Consecutive Sum
1733B - Rule of League
1733C - Parity Shuffle Sorting
1264A - Beautiful Regional Contest
1695A - Subrectangle Guess
467B - Fedor and New Game
252C - Points on Line